/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import beans.DBMS;
import beans.item;
import com.sun.org.apache.bcel.internal.generic.D2F;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.ListIterator;

/**
 *
 * @author appi
 */
public class itemdao {
    public static ArrayList<item> getAllItem()
    {
      ResultSet rs=null;
      ArrayList<item> ai=new ArrayList<item>();
      DBMS d=new DBMS(); 
      String sql="select * from items";
      rs=d.gselect(sql);
      try
      {
      while(rs.next())
      {
          //here one object represant one raw and its getting from database
          item i=new item();
                
             i.setId(rs.getInt("iid"));
             i.setIname(rs.getString("iname"));
             i.setIprice(rs.getFloat("iprice"));
            // i.setIurl(rs.getString("iurl"));
             i.setIsdesc(rs.getString("isdesc"));
             i.setIddesc(rs.getString("iddesc"));
             i.setIstock(rs.getInt("istock"));
             ai.add(i); // here all iterms all attributes goes in arraylist...
      }
     
      }
      catch(Exception e)
      {
          e.printStackTrace();
      }
      return ai;
    }
    public static Boolean updateItem(item ui)
    {
        Boolean flag=false;
        DBMS d=new  DBMS();
        String sql="update items set iname='"+ui.getIname()+"',iprice='"+ui.getIprice()+"',istock='"+ui.getIstock()+"',isdesc='"+ui.getIsdesc()+"',iddesc='"+ui.getIddesc()+"' where iid='"+ui.getId()+"'";
        if(d.guid(sql)==1)
        {
           flag=true; 
        }
        return flag;
    }
    public static Boolean deleteItem(item di)
    {
        boolean flag=false;
        DBMS d=new DBMS();
        String sql="delete from items where iid='"+di.getId()+"'";
        if(d.guid(sql)==1)
        {
            flag=true;
        }
        return flag;
    }
}
              
              
              
              
              
              
              
              
              
              
              
          
    
    

    
    

